//
//  AppDelegate.m
//  07-UITabBarController
//
//  Created by dllo on 16/7/22.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [_window makeKeyAndVisible];
#pragma mark - 主要管理没有层级关系的视图控制器
    // viewControllers 管理的视图控制器都在这个数组里
    // setViewControllers:animated: 也可以用setter方法创建
    // tabBarItem 为懒加载的创建方式,setter可以为空,但是getter 不为空,参考修饰符(null_resettable) ,实际上它为ViewController的类目的属性,它 有多种初始化创建方法
    // 数组个数多余5个,后面显示不出来
    UITabBarController *tab = [UITabBarController new];
    _window.rootViewController = tab;
    
    ViewController *vc = [ViewController new];
    vc.view.backgroundColor = [UIColor redColor];
//    vc.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1000];
    ViewController *vc1 = [ViewController new];
    ViewController *vc2 = [ViewController new];
    ViewController *vc3 = [ViewController new];
    ViewController *vc4 = [ViewController new];
    vc1.view.backgroundColor = [UIColor colorWithRed:0.171 green:0.151 blue:0.436 alpha:1.000];
    vc2.view.backgroundColor = [UIColor colorWithRed:0.976 green:1.000 blue:0.378 alpha:1.000];
    vc3.view.backgroundColor = [UIColor colorWithRed:0.274 green:1.000 blue:0.962 alpha:1.000];
    vc4.view.backgroundColor = [UIColor colorWithRed:0.265 green:0.083 blue:1.000 alpha:1.000];
    vc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"2" image:[[UIImage imageNamed:@"lv2_s"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]selectedImage:[[UIImage imageNamed:@"lv2_v_s"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    vc2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"3" image:[[UIImage imageNamed:@"quan03@2x 2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]selectedImage:[[UIImage imageNamed:@"lv3_v_s"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
                      
    vc3.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"4" image:[[UIImage imageNamed:@"lv4_s"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"lv4_v_s"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    vc4.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"5" image:[[UIImage imageNamed:@"lv5_s"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"lv5_v_s"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    // tabBar(高度49)
    // barTintColor 背景颜色
    // tintColor 元素颜色
    tab.tabBar.barTintColor = [UIColor greenColor];
    tab.tabBar.tintColor = [UIColor yellowColor];
    // 装载UINavigationController 在vc 上
    UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:vc];
    // 给tabBarItem 设置时,给最靠近的视图控制器设置,不要跨级,当放navc时,用navc去设置,当放vc时,用vc去设置,
    navc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"1" image:[[UIImage imageNamed:@"lv1_s"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"lv1_v_s"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//    vc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"不行" image:nil selectedImage:nil];
    // tabBarItem.title 设置的是navc 的tabBar的 title
    //navc.tabBarItem.title = @"下";
    // navigationItem 设置的是vc 的navigationItem的 title
    vc.navigationItem.title = @"上";
    // title 这个属性是针对vc的,不是针对navc的
    // 小属性
    vc.tabBarItem.badgeValue = @"999+";
    [tab setViewControllers:@[navc,vc1,vc2,vc3,vc4] animated:YES];
    tab.tabBar.backgroundImage = [UIImage imageNamed:@"new_user_recommend_cell_bg2"];
    // UIAppearance 全局设置外观
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"player_icon_mvPreview"] forBarMetrics:UIBarMetricsDefault];
//    vc.title = @"你好";
    // 修改系统的标题颜色
    // 方法一:自定义titleview ,上面放label,改变颜色
    //  方法二: 用UIAppearance
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    //  在viewController 中写上 self.title 和self.navigationItem.title 有区别
    // 前者统一修改上下title ,navigationItem.title 和tabBarItem.title
    // 后者只修改navigationbar上navigationItem的标题
    // 所以不推荐那么写
    
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
